﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AnaViewer
{
    /// <summary>
    /// 言兑网相关操作。
    /// </summary>
    public class Yandui
    {
        static Dictionary<string, string> types;
        public static Dictionary<string, string> Types
        {
            get { return types; }
        }
        static Yandui()
        {
            types = new System.Collections.Generic.Dictionary<string, string>();
            types.Add("言兑推荐语录", "GetTuiJianAnaXml");
            types.Add("最新发布语录", "GetNewAnaXml");
            types.Add("最近喜欢语录", "GetNewLikeAnaXml");
            types.Add("最近收藏语录", "GetNewCollectionAnaXml");
            types.Add("最近评论语录", "GetNewCommentAnaXml");
            types.Add("喜欢最多语录", "GetHotAnaXml");
            types.Add("收藏最多语录", "GetCollectionMaxAnaXml");
            types.Add("评论最多语录", "GetCommentMaxAnaXml");
            types.Add("指定人物类别语录", "GetPersonSortAnaXml");
            types.Add("指定语录标签语录", "GetAnaTagAnaXml");
            types.Add("指定来源类别语录", "GetAnaOriginAnaXml");
        }

        public static void GoHome()
        {
            Common.GoUrl("http://www.yandui.com/");
        }

        /// <summary>
        /// 查看人物，格式：http://www.yandui.com/renwu/9922/
        /// </summary>
        /// <param name="renwuId"></param>
        public static void GoUrl_RenwuView(string renwuId)
        {
            Common.GoUrl(string.Format("http://www.yandui.com/renwu/{0}/", renwuId));
        }
        /// <summary>
        /// 搜索人物，格式：http://www.yandui.com/search/SeacrchFriend.aspx?nickname=%E9%9D%9E%E8%8A%B1%E9%9D%9E&x=45&y=14
        /// http://www.yandui.com/search/SeacrchPerson.aspx?Word=%e9%9d%9e%e8%8a%b1%e9%9d%9e
        /// </summary>
        /// <param name="name"></param>
        public static void GoUrl_RenwuSerch(string name)
        {
            Common.GoUrl(string.Format("http://www.yandui.com/search/SeacrchPerson.aspx?Word={0}", System.Web.HttpUtility.UrlEncode(name)));
        }

        /// <summary>
        /// 查看语录，格式：http://www.yandui.com/yulu/52616/
        /// </summary>
        /// <param name="id"></param>
        public static void GoUrl_YuluView(string id)
        {
            Common.GoUrl(string.Format("http://www.yandui.com/yulu/{0}/", id));
        }
        /// <summary>
        /// 编辑语录，格式：http://www.yandui.com/Ana/SendEditAna.aspx?Type=Edit&AnaId=52616
        /// </summary>
        /// <param name="id"></param>
        public static void GoUrl_YuluEdit(string id)
        {
            Common.GoUrl(string.Format("http://www.yandui.com/Ana/SendEditAna.aspx?Type=Edit&AnaId={0}", id));
        }
        /// <summary>
        /// 评论语录，格式：http://www.yandui.com/yulu/2781/#comment_content
        /// </summary>
        /// <param name="id"></param>
        public static void GoUrl_YuluComment(string id)
        {
            Common.GoUrl(string.Format("http://www.yandui.com/yulu/{0}/#comment_content", id));
        }
        /// <summary>
        /// 获取指定语录集合的地址。 输入的字符串格式类似于：“最新发布语录”
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        internal static string GetAnaUrl(string showText)
        {
            string result = "";
            if (types.ContainsKey(showText))
                 result = types[showText];
            else
                result = "GetHotAnaXml";//默认 喜欢最多的语录

            return @"http://www.yandui.com/Xml/Api/GetAna.aspx?type=" + result;
        }
    }
}
